<%@ page import="com.cyj.entity.Admin" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/12/13
  Time: 10:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>编辑管理员个人资料</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <script src="<%=request.getContextPath()%>/static/js/jquery-3.4.1.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/static/css/bootstrap.css" />
    <script src="<%=request.getContextPath()%>/static/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/static/css/button.css" />
    <script type="text/javascript">
        var system ={};
        var p = navigator.platform;
        system.win = p.indexOf("Win") == 0;
        system.mac = p.indexOf("Mac") == 0;
        system.x11 = (p == "X11") || (p.indexOf("Linux") == 0);
        if(system.win||system.mac||system.xll){//如果是电脑跳转到
            window.location.href="#";
        }else{  //如果是手机,跳转到
            window.location.href="${pageContext.request.contextPath}/index.jsp";
        }
    </script>
    <style type="text/css">

    </style>
</head>

<body>

<!-- 导航条-->
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
                <span class="sr-only">切换导航栏</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#" style="padding: 0px;">

            </a>
        </div>

        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
                <p class="nav navbar-text"><span>管理员：${admin.adminName}</span></p>
                <p class="nav navbar-text"><span id="times"></span></p>
                <a class="nav navbar-text" href="${pageContext.request.contextPath}/admin/adminMainView"><span class="glyphicon glyphicon-home">首页</span></a>
                <button class="btn btn-danger navbar-btn" id="logout">
                    <span class="glyphicon glyphicon-off"></span>退出登录
                </button>
            </ul>

        </div>

    </div>
</nav>

<!-- 主体部分 -->
<div class="container-fluid">
    <div class="row">

        <!--左边部分 -->
        <div class="col-md-3">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <!-- 头像 -->
                    <div class="top-section" id="headPicture">
                        <div class="profile-image">
                            <a href="${pageContext.request.contextPath}/admin/adminDetails">
                                <img src="${admin.picture}" class="img-circle center-block" width="150px" height="150px">
                            </a>
                        </div>
                        <div class="profile-content">
                            <h3 class="profile-title text-center">${admin.adminName}</h3>
                            <p class="profile-description text-center">${admin.signature}</p>
                        </div>
                    </div>
                </div>

                <div class="panel-body">
                    <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">

                        <div class="panel panel-default" id="bodyList">
                            <div class="list-group">
                                <a href="${pageContext.request.contextPath}/user/users" class="list-group-item text-center">二次元用户管理</a>
                                <a href="${pageContext.request.contextPath}/anime/animes" class="list-group-item text-center">动漫信息管理</a>
                                <a href="${pageContext.request.contextPath}/region/regions" class="list-group-item text-center">发行地区管理</a>
                                <a href="${pageContext.request.contextPath}/type/types" class="list-group-item text-center">动漫类型管理</a>
                                <a href="${pageContext.request.contextPath}/enshrine/enshrines" class="list-group-item text-center">追番管理</a>
                                <a href="${pageContext.request.contextPath}/comment/comments" class="list-group-item text-center">评论管理</a>
                                <a href="${pageContext.request.contextPath}/admin/adminDetails" class="list-group-item text-center">编辑个人资料</a>
                            </div>
                        </div>

                    </div>
                </div>

                <div class="panel-footer">
                    <div class="box bg-1">
                        <button class="button button--antiman button--round-l button--text-medium" onclick="window.open('${pageContext.request.contextPath}/index.jsp')"><span>转到前台</span></button>
                    </div>
                </div>
            </div>

        </div>


        <!--右边部分 -->
        <div class="col-md-9">
            <div>
                <div class="panel panel-default">
                    <div class="page-header">
                        <!-- 头像 -->
                        <div class="top-section">
                            <div class="profile-image">
                                <img src="${admin.picture}" class="img-circle center-block" width="150px" height="150px">
                            </div>
                            <div class="profile-content">
                                <button class="btn btn-default center-block" data-toggle="modal" data-target="#exampleModal2" data-whatever="上传动漫封面" id="upload"><span class="glyphicon glyphicon-edit" ></span>上传头像</button>
                            </div>
                        </div>

                    </div>

                    <div class="panel-body">
                        <div class="col-md-4">

                        </div>

                        <div class="col-md-8">
                            <table class="center-block">
                                <tr style="line-height: 15px">
                                    <td><h4><span class="text-right">管理员Id：</span></h4></td>
                                    <td><h4><span class="text-left">${admin.adminId}</span></h4></td>
                                </tr>

                                <tr style="line-height: 15px">
                                    <td><h4><span class="text-right">管理员名：</span></h4></td>
                                    <td><h4><span class="text-left">${admin.adminName}</span></h4></td>
                                </tr>

                                <tr style="line-height: 15px">
                                    <td><h4><span class="text-right">手机号：</span></h4></td>
                                    <td><h4><span class="text-left">${admin.phone}</span></h4></td>
                                </tr>

                                <tr style="line-height: 15px">
                                    <td><h4><span class="text-right">年龄：</span></h4></td>
                                    <td><h4><span class="text-left">${admin.age}</span></h4></td>
                                </tr>

                                <tr style="line-height: 15px">
                                    <td><h4><span class="text-right">性别：</span></h4></td>
                                    <td><h4><span class="text-left">${admin.sex}</span></h4></td>
                                </tr>

                                <tr style="line-height: 15px">
                                    <td><h4><span class="text-right">个性签名：</span></h4></td>
                                    <td><h4><span class="text-left">${admin.signature}</span></h4></td>
                                </tr>

                                <tr style="line-height: 15px">
                                    <td><h4><span class="text-right">创号时间：</span></h4></td>
                                    <td><h4><span class="text-left">${admin.createTime}</span></h4></td>
                                </tr>

                                <tr style="line-height: 15px">
                                    <td><h4><span class="text-right">最后登录时间：</span></h4></td>
                                    <td><h4><span class="text-left">${admin.lastLoginTime}</span></h4></td>
                                </tr>


                                <tr>
                                    <td colspan="2"> <button class="btn btn-danger" data-toggle="modal" data-target="#exampleModal" data-whatever="修改管理员信息" id="update"><span class="glyphicon glyphicon-edit" ></span>点击修改</button></td>
                                </tr>
                            </table>
                        </div>



                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

<!--增加、修改、查看详情弹框-->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="exampleModalLabel">New message</h4>
            </div>

            <div class="modal-body">
                <div class="center-block">
                    <form class="form-horizontal" id="Form" enctype="multipart/form-data">

                        <!-- adminId  -->
                        <div class="form-group">
                            <label for="adminId" class="col-sm-3 control-label">管理员Id：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control adminId" id="adminId" placeholder="管理员Id" name="adminId" required="required" disabled="disabled"/>
                            </div>
                        </div>

                        <!-- adminName  -->
                        <div class="form-group">
                            <label for="adminName" class="col-sm-3 control-label">管理员名：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control adminName" id="adminName" placeholder="姓名" name="adminName" required="required"/>
                            </div>
                        </div>

                        <!--  adminPassword -->
                        <div class="form-group">
                            <label for="adminPassword" class="col-sm-3 control-label">密码:</label>
                            <div class="col-sm-9">
                                <input type="password" class="form-control adminPassword" id="adminPassword" placeholder="密码" name="adminPassword" required="required"/>
                            </div>
                        </div>


                        <!-- phone  -->
                        <div class="form-group">
                            <label for="phone" class="col-sm-3 control-label">手机号：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control phone" id="phone" placeholder="手机号" name="phone" required="required"/>
                            </div>
                        </div>

                        <!-- age  -->
                        <div class="form-group">
                            <label for="age" class="col-sm-3 control-label">年龄：</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control age" id="age" placeholder="年龄" name="age" required="required"/>
                            </div>
                        </div>

                        <!-- sex  -->
                        <div class="form-group">
                            <label for="sex" class="col-sm-3 control-label">性别：</label>
                            <div class="col-sm-9">
                                <select class="form-control sex" id="sex" name="sex">
                                    <option value="-1">请选择性别</option>
                                    <option value="0">男</option>
                                    <option value="1">女</option>
                                </select>
                            </div>
                        </div>

                        <!-- signature  -->
                        <div class="form-group">
                            <label for="signature" class="col-sm-3 control-label">个性签名：</label>
                            <div class="col-sm-9">
                                <textarea class="form-control signature" id="signature" rows="3" name="signature"></textarea>
                            </div>
                        </div>

                    </form>
                </div>

            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary save" id="save">确定</button>
                <button type="button" class="btn btn-primary update " style="display: none;">修改</button>
            </div>
        </div>
    </div>
</div>

<!--上传图片弹框-->
<div class="modal fade" id="exampleModal2" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel2" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="exampleModalLabel2">上传头像</h4>
            </div>

            <div class="modal-body">
                <form class="form-horizontal" id="uploadForm" enctype="multipart/form-data">

                    <div class="form-group divHide">
                        <label for="uploadFile" class="col-sm-3 control-label">管理员头像：</label>
                        <div class="col-sm-5">
                            <input type="file" class="form-control" placeholder="" name="uploadFile" id="uploadFile" multiple="multiple">
                        </div>
                    </div>

                </form>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary upload" >上传</button>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    //得到时间并写入div
    function getDate(){
        //获取当前时间
        var date = new Date();
        //格式化为本地时间格式
        var date1 = date.toLocaleString();
        //获取div
        var span = document.getElementById("times");
        //将时间写入div
        span.innerHTML = date1;
    }
    //使用定时器每秒向div写入当前时间
    setInterval("getDate()",1000);


    $(function () {
        //弹窗部分
        $('#exampleModal').on('show.bs.modal', function(event) {
            var button = $(event.relatedTarget);
            var recipient = button.data('whatever');

            var modal = $(this);
            modal.find('.modal-title').text(recipient);
//				modal.find('.modal-body input').val(recipient);
        })

        /*数据回显*/
        $(document).on("click", "#update", function() {

            var adminId = ${admin.adminId};
            console.log(adminId);

            $(".divHide").show();
            $(".update").show();
            $("#save").hide();

            $.post("${pageContext.request.contextPath}/admin/adminBy", {
                adminId: adminId
            }, function(data) {
                console.log(data);
                //将后台返回的数据给对应的表单元素赋值
                $(".adminId").val(data.data.adminId);
                $(".adminName").val(data.data.adminName);
                $(".adminPassword").val(data.data.adminPassword);
                $(".phone").val(data.data.phone);
                $(".sex").val(data.data.sex);
                $(".age").val(data.data.age);
                $(".signature").val(data.data.signature);
                $(".createTime").val(data.data.createTime);
                $(".lastLoginTimeTime").val(data.data.lastLoginTime);
            }, "json")
        });

        /*修改操作*/
        $(document).on("click", ".update", function() {
            var adminId = ${admin.adminId};
            console.log(adminId);

            console.log($("#Form").serialize());

            $.ajax({
                type: "POST",
                data: $("#Form").serialize(),
                url: "${pageContext.request.contextPath}/admin/updateAdmin?adminId="+adminId,
                dataType: "json",
                success: function(data) {
                    console.log(data);
                    if(data.code == 200) {
                        alert(data.msg);
                        $("#myModalLabel").modal("hide");
                        window.location.reload();
                    } else {
                        alert(data.msg);
                    }

                }
            })

        })

        /*上传操作*/
        $(document).on("click", "#upload", function() {

            var adminId = ${admin.adminId};
            console.log(adminId);


            $(document).on("click", ".upload", function() {

                var formData = new FormData($("#uploadForm")[0]);
                console.log(formData);

                $.ajax({
                    type: "POST",
                    data: formData,
                    url: "${pageContext.request.contextPath}/admin/uploadPicture?adminId="+adminId,
                    dataType: "json",
                    processData:false,
                    contentType:false,
                    success: function(data) {
                        console.log(data);
                        if(data.code == 200) {
                            alert(data.msg);
                            $("#myModalLabel").modal("hide");
                            window.location.reload();
                        } else {
                            alert(data.msg);
                        }
                    }
                })
            })

        })

        //退出登录
        $(document).on("click", "#logout", function() {
            if(confirm('是否要退出登录？')) {
                $.get(
                    "${pageContext.request.contextPath}/admin/logout",
                    function(data) {
                        window.location.reload();
                    }, "json")
            }
        })


    })
</script>

</html>
